package com.qst.mapreduce.wordcount.taobao;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class InfoReducer extends Reducer<Text, App,Text, App> {
    @Override
    protected void reduce(Text key, Iterable<App> values, Reducer<Text, App, Text, App>.Context context) throws IOException, InterruptedException {
        int count=0;
        int tatolBrowseCount=0;
        double tatolCTR=0;
        for (App value : values){
            tatolBrowseCount+=value.getBrowseCount();
            tatolCTR+=value.getCTR();
            count++;

        }
        App outapp = new App();
        outapp.setBrowseCount(tatolBrowseCount/count);
        outapp.setCTR(tatolCTR/count);
        context.write(key,outapp);
    }
}
